package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.CaseDataStatus;
import cn.fintecher.pangolin.common.enums.CaseLeaveFlag;
import cn.fintecher.pangolin.common.enums.CaseType;
import cn.fintecher.pangolin.common.enums.PayStatus;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import cn.fintecher.pangolin.service.business.model.BaseQueryRequest;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @Author wangxiangdong
 * @Description 留案案件request
 * @Date 2019/9/17 14:53
 **/
@Data
public class LeaveCaseRequest extends BaseQueryRequest {

    @ApiModelProperty(value = "还款状态")
    private PayStatus payStatus;

    @ApiModelProperty(notes = "系统自动设置状态")
    private CaseDataStatus caseStatus;

    @ApiModelProperty(value = "催收状态")
    private String collectStatus;

    @ApiModelProperty(value = "催收员")
    private String currentCollectorName;

    @ApiModelProperty(value = "部门code")
    private String departCode;

    @ApiModelProperty(notes = "催计数总数")
    private Integer collectionTotalRecordCount;

    @ApiModelProperty(value = "案件类型")
    private CaseType caseType;

    public BooleanBuilder generateBooleanBuilder() {
        BooleanBuilder booleanBuilder = generateBaseQueryBuilder();
        QCaseInfo qCaseInfo = QCaseInfo.caseInfo;
        booleanBuilder.and(qCaseInfo.leaveFlag.eq(CaseLeaveFlag.HAS_LEAVE));
        if (Objects.nonNull(this.payStatus)) {
            booleanBuilder.and(qCaseInfo.payStatus.eq(this.payStatus));
        }
        if (Objects.nonNull(this.collectStatus)) {
            booleanBuilder.and(qCaseInfo.collectStatus.eq(this.collectStatus));
        }
        if (Objects.nonNull(this.caseStatus)) {
            booleanBuilder.and(qCaseInfo.caseStatus.eq(this.caseStatus));
        }
        if (Objects.nonNull(this.currentCollectorName)) {
            booleanBuilder.and(qCaseInfo.currentCollector.realName.like(StringUtils.join(this.currentCollectorName, "%")));
        }
        if (Objects.nonNull(this.departCode)) {
            booleanBuilder.and(qCaseInfo.currentCollector.department.departCode.like(StringUtils.join(this.departCode, "%")));
        }
        if (Objects.nonNull(this.collectionTotalRecordCount)) {
            booleanBuilder.and(qCaseInfo.collectionTotalRecordCount.eq(this.collectionTotalRecordCount));
        }
        if (Objects.nonNull(this.caseType)) {
            booleanBuilder.and(qCaseInfo.caseType.eq(this.caseType));
        }
        return booleanBuilder;
    }
}
